package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/2.
 */
@HttpInlet(Conn.FEEDBACK_GET)
public class FeedbackDetailListGet extends BaseAsyGet<FeedbackDetailListGet.FeedbackDetialEntity> {

    public String user_id;

    public int page;

    public FeedbackDetailListGet(AsyCallBack<FeedbackDetialEntity> asyCallBack) {
        super(asyCallBack);
    }


    @Override
    protected FeedbackDetialEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONObject objectMain = object.optJSONObject("data");
            FeedbackDetialEntity feedbackDetialEntity = new FeedbackDetialEntity();

            feedbackDetialEntity.current_page = objectMain.optInt("current_page");
            feedbackDetialEntity.per_page = objectMain.optInt("per_page");
            feedbackDetialEntity.total = objectMain.optInt("total");

            JSONArray array = objectMain.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                FeedbackDetail feedbackDetail = new FeedbackDetail();

                JSONObject detailObject = array.optJSONObject(i);

                feedbackDetail.id = detailObject.optString("id");
                feedbackDetail.uid = detailObject.optString("uid");
                feedbackDetail.phone = detailObject.optString("phone");
                feedbackDetail.content = detailObject.optString("content");
                feedbackDetail.posttime = detailObject.optString("posttime");
                feedbackDetail.ip = detailObject.optString("ip");
                feedbackDetail.reply = detailObject.optString("reply");
                feedbackDetail.recovery_time = detailObject.optString("recovery_time");
                feedbackDetail.re_name = detailObject.optString("re_name");

                feedbackDetialEntity.feedbackDetailList.add(feedbackDetail);

            }

            return feedbackDetialEntity;

        }

        return null;

    }

    public static class FeedbackDetialEntity {

        public int total, per_page, current_page;

        public List<FeedbackDetail> feedbackDetailList = new ArrayList<>();

    }


    public static class FeedbackDetail {

        public String id, uid, phone, content, posttime, ip, reply, recovery_time, re_name;

    }

}
